| Conditions | 1 |
| Paths | 1 |
| Total Lines | 118 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import expect from 'expect'; |
||
| 6 | describe('The selection model class', () => { |
||
| 7 | |||
| 8 | const plugins = {}; |
||
| 9 | const stateKey = 'test-grid'; |
||
| 10 | const events = {}; |
||
| 11 | |||
| 12 | it('Should return a selection model with defaults', () => { |
||
| 13 | |||
| 14 | const model = new Model(); |
||
| 15 | |||
| 16 | model.init( |
||
| 17 | plugins, stateKey, store, events |
||
| 18 | ); |
||
| 19 | |||
| 20 | expect(model).toBeTruthy(); |
||
| 21 | |||
| 22 | expect( |
||
| 23 | model.defaults |
||
| 24 | ).toEqual({ |
||
| 25 | mode: 'single', |
||
| 26 | activeCls: 'active', |
||
| 27 | allowDeselect: true, |
||
| 28 | editCls: 'edit', |
||
| 29 | editEvent: 'none', |
||
| 30 | enabled: true, |
||
| 31 | selectionEvent: 'singleclick', |
||
| 32 | store |
||
| 33 | }); |
||
| 34 | |||
| 35 | }); |
||
| 36 | |||
| 37 | it('Should return a selection model with joined props', () => { |
||
| 38 | |||
| 39 | const model = new Model(); |
||
| 40 | |||
| 41 | const joined = { |
||
| 42 | SELECTION_MODEL: { |
||
| 43 | mode: 'checkbox-single', |
||
| 44 | allowDeselect: false |
||
| 45 | } |
||
| 46 | }; |
||
| 47 | |||
| 48 | model.init( |
||
| 49 | joined, stateKey, store, events |
||
| 50 | ); |
||
| 51 | |||
| 52 | expect(model).toBeTruthy(); |
||
| 53 | |||
| 54 | expect( |
||
| 55 | model.defaults |
||
| 56 | ).toEqual({ |
||
| 57 | mode: 'checkbox-single', |
||
| 58 | activeCls: 'active', |
||
| 59 | allowDeselect: false, |
||
| 60 | editCls: 'edit', |
||
| 61 | editEvent: 'none', |
||
| 62 | enabled: true, |
||
| 63 | selectionEvent: 'singleclick', |
||
| 64 | store |
||
| 65 | }); |
||
| 66 | |||
| 67 | }); |
||
| 68 | |||
| 69 | it('Should fire selection events', () => { |
||
| 70 | |||
| 71 | const model = new Model(); |
||
| 72 | |||
| 73 | const customEvents = { |
||
| 74 | HANDLE_BEFORE_SELECTION: sinon.spy(), |
||
| 75 | HANDLE_BEFORE_BULKACTION_SHOW: sinon.spy(), |
||
| 76 | HANDLE_AFTER_SELECTION: sinon.spy(), |
||
| 77 | HANDLE_AFTER_BULKACTION_SHOW: sinon.spy() |
||
| 78 | }; |
||
| 79 | |||
| 80 | const selectionEvent = { |
||
| 81 | id: 'some-id', |
||
| 82 | index: 4 |
||
| 83 | }; |
||
| 84 | |||
| 85 | model.init( |
||
| 86 | plugins, stateKey, store, customEvents |
||
| 87 | ); |
||
| 88 | |||
| 89 | expect(model).toBeTruthy(); |
||
| 90 | |||
| 91 | model.handleSelectionEvent(selectionEvent); |
||
| 92 | |||
| 93 | expect( |
||
| 94 | customEvents.HANDLE_BEFORE_SELECTION.called |
||
| 95 | ).toEqual(true); |
||
| 96 | |||
| 97 | expect( |
||
| 98 | customEvents.HANDLE_BEFORE_BULKACTION_SHOW.called |
||
| 99 | ).toEqual(true); |
||
| 100 | |||
| 101 | expect( |
||
| 102 | customEvents.HANDLE_AFTER_SELECTION.called |
||
| 103 | ).toEqual(true); |
||
| 104 | |||
| 105 | expect( |
||
| 106 | customEvents.HANDLE_AFTER_BULKACTION_SHOW.called |
||
| 107 | ).toEqual(true); |
||
| 108 | |||
| 109 | const selectionState = store |
||
| 110 | .getState() |
||
| 111 | .selection.get('test-grid'); |
||
| 112 | |||
| 113 | expect( |
||
| 114 | selectionState.get('some-id') |
||
| 115 | ).toEqual(true); |
||
| 116 | |||
| 117 | expect( |
||
| 118 | selectionState.get('indexes').toJS() |
||
| 119 | ).toEqual([4]); |
||
| 120 | |||
| 121 | }); |
||
| 122 | |||
| 123 | }); |
||
| 124 |